<template>
	<div>
		 <Tabs type="card" :animated="false" @on-click="tabsSwitch">
	        <TabPane label="待审核">
					<!--<Input v-model="value" placeholder="请输入..." style="width: 300px"></Input> 
					<Button type="primary" :loading="loading" @click="search">搜索</Button>
					<div style="margin:16px 16px 16px 0;">
						<Row>
							<Col span="4"><h3>组织架构</h3></Col>
							<Col span="8"><Button type="primary" icon="person-add" @click="add">新增</Button></Col>
						</Row>
					</div>-->
				    <Table border  :loading="loading" :columns="columns1" :data="list"></Table>
				    <Page :total="page.total" :page-size="page.pageSize" show-total @on-change="changePage"></Page>
	        </TabPane>
	        <TabPane label="已审核">
				    <Table border  :loading="loading" :columns="columns2" :data="list"></Table>
				    <Page :total="page.total" :page-size="page.pageSize" show-total @on-change="changePage"></Page>
	        </TabPane>
	    </Tabs>
		<ReviewDes :info="info"  @upup="refreshData"></ReviewDes>
	</div>
</template>

<script>
	import ReviewDes from './reviewDes.vue';
    export default {
        data () {
            return {
            	loading: false,
            	value:"",
            	status:1,
            	info:{
            		id:"",
            		title:"",
            		show:false,
            		status:1,
            		formItem: {
					},
            	},
            	list:[],
				page:{
            		pageNo:0,
            		total:0,
            		pageSize:4
            	},
                columns: [
                    {
                        title: '用户编号',
                        key: 'user_code',
                    },
                    {
                        title: '公司名称',
                        key: 'hotel_name'
                    },
                    {
                        title: '行业',
                        key: 'industry'
                    },
                    {
                        title: '销售人员',
                        key: 'referrer'
                    },
                    {
                        title: '申请时间',
                        key: 'apply_for_time'
                    },
                    {
                        title: '状态',
                        key: 'account_status',
                        render: (h, params) => {
	                        let _account_status={"1":"待审核","2":"审核未通过","4":"试用中"}
                        	return h('span',_account_status[params.row.account_status])
                        }
                    }
                ]
            }
        },
        components:{
        	ReviewDes
        },
       computed: {
	    columns1(){
	    	let opt1=[
        	{
            	title: '操作',
                key: 'action',
                align: 'center',
                width:230,
                render: (h, params) => {
                	return h('div', [
                        h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.showDes(params.row.id)
                                }
                            }
                        }, '详情'),
                        h('Button', {
                            props: {
                                type: 'success',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.pass(params.row.id)
                                }
                            }
                        }, '审核通过'),
                         h('Button', {
                            props: {
                                type: 'warning',
                                size: 'small'
                            },
                            on: {
                                click: () => {
                                    this.notPass(params.row.id)
                                }
                            }
                        }, '审核不通过')
                    ]);
                }
            }]
	      return [...this.columns,...opt1];
	    },
	    columns2(){
	    	let opt2=[
            {
            	title: '操作',
                key: 'action',
                align: 'center',
                render: (h, params) => {
            		return h('div', [
                        h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.showDes(params.row.id)
                                }
                            }
                        }, '详情'),
                    ]);
            	}
            }]
	      return [...this.columns,...opt2];
	    }
	  },
        methods: {
        	tabsSwitch(name){
        		if(name==0){
        			this.status="1";
        			this.info.status="1";
        			this.refreshData();
        		}else{
        			this.status="2,4";
        			this.info.status="2";
        			this.refreshData();
        		}
        	},
        	refreshData(){
        		this.$ajax({
					url: "/user_management/audit/"+this.status,
					method: "get",
					data:{
						"page": this.page.pageNo,
						"size": this.page.pageSize,
						"conditions":""
					}
				}).then((d) => {
	//				this.loading=false;
					this.page.total=d.total;
					this.list=d.data;
					console.log(d)
				})
        	},
        	changePage(page){
        		this.page.pageNo=page-1;
        		this.refreshData();
        	},
            showDes(index) {
            	console.log(index)
            	this.$ajax({
					url: "/user_management/detail/"+index,
					method: "get",
					data:{
					}
				}).then((d) => {
	//				this.loading=false;
					this.info.title="未审核";
					this.info.formItem=d.data;
					this.info.id=index;
					this.info.show=true;
					console.log(d);
				})
            },
            pass (index) {
                this.$Modal.confirm({
                    title: '确认审核通过',
                    content: '<p>是否确认审核通过</p>',
                    onOk: () => {
                        this.$ajax({
							url: "/user_management/auditPass/"+index,
							method: "get",
							data: ""
						}).then((d) => {
							if(d.message==="success"){
								this.$Message.success('审核通过成功');
								this.refreshData()
							}else{
								this.$Message.warning(d.message);
								this.refreshData();
							}
						})
                    },
                    onCancel: () => {
                    }
                });
            },
            notPass (index) {
            	 this.$Modal.confirm({
                    title: '确认审核不通过',
                    content: '<p>是否确认审核不通过</p>',
                    onOk: () => {
                        this.$ajax({
							url: "/user_management/auditNotPass/"+index,
							method: "get",
							data: ""
						}).then((d) => {
							if(d.message==="success"){
								this.$Message.success('审核不通过成功');
								this.refreshData()
							}else{
								this.$Message.warning(d.message);
								this.refreshData();
							}
						})
                    },
                    onCancel: () => {
                    }
                });
            },
       },
       mounted() {
			this.$ajax({
				url: "/user_management/audit/"+this.status,
				method: "get",
				data:{
					"page": this.page.pageNo,
					"size": this.page.pageSize,
					"conditions":""
				}
			}).then((d) => {
//				this.loading=false;
				this.page.total=d.total;
				this.list=d.data;
				console.log(d)
			})
		}
    }
</script>
<style>
</style>